clear
***set working directory

use us-capex-imputation.dta, clear

#delimit ;
global covars="gwf_personal allexp gtime lgdpcap lpop lopenness grow 
incidencev413 meanreserves ldevelopingfdi asia americas easia ssa"; 
#delimit cr

* Imputed Data
* Model 1: execute lines 27-42 to retrieve estimated coefficients for the 10 imputed data sets
* Use us_capex_imputation.R to combine the estimated coefficients to obtain final results

**Nonimputed Data
* Model 2 in Table M-1
xtregar cub_capexgdp $covars, re 

* Model 3 in Table M-1
xtregar cub_capexgdp $covars if cub_capexgdp<.47, re 


********************************************************************************
** retrieve estimated coefficients for the 10 imputed data sets
clear

! dir us_capex*.csv /a-d /b > filelist1.txt

* command started with "file"* execute lines 30-42 together
file open myfile using "filelist1.txt", read
file read myfile line
local replace "replace" 
while r(eof)==0 {
 import delimited `line',clear
 xtset cowcode year
 xtregar cub_capexgdp $covars, re
 regsave $covars _cons using us_capex_coefs.dta, ci level(95) `replace'
 local replace "append"
 file read myfile line
}
**
file close myfile
